package com.njupt.Collection;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 2506165018
 * @version 1.0
 * @data 2025-07-29 16:48:24
 */

class User{

    String name;

    Integer age;

    User(String name,Integer age){
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class CollectSorted {



    public static void main(String[] args) {
        List<User> list = new ArrayList<>();
        User user1 = new User("wjm", 18);
        User user2 = new User("xfy", 19);
        User user3 = new User("wzx", 20);
        User user4 = new User("lh", 10);
        list.add(user1);
        list.add(user2);
        list.add(user3);
        list.add(user3);
        list.add(user4);

        List<User> collect = list.stream().filter(user -> user.age > 10).sorted((u1, u2) -> {

            return u1.age - u2.age;
        }).collect(Collectors.toList());
        System.out.println(collect);

        List<User> collect1 = list.stream().filter(user -> user.age > 10).sorted((u1, u2) -> {
            return u1.age - u2.age;
        }).distinct().collect(Collectors.toList());

        System.out.println(collect1);

        boolean b = list.stream().allMatch(user -> "wjm".equals(user.getName()));
        System.out.println(b);

        Integer reduce = list.stream().map(user -> user.getAge()).reduce(0, (u1, u2) -> {
            return u1 + u2;
        });
        System.out.println(reduce);
    }
}
